package controllers

import (
	"meituan/apps/shop/models"
	db2 "meituan/db"
	"strconv"

	"github.com/gin-gonic/gin"
)

func ListShop(ctx *gin.Context) {
	shops := make([]models.Shop, 10)
	db, _ := db2.NewDB()
	defer db.Close()
	db.Model(&models.Shop{}).Omit("category_id").Find(&shops)
	ctx.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": shops,
	})
}

func DeleteShop(ctx *gin.Context) {
	id := ctx.Param("id")
	if num, isNum := strconv.Atoi(id); isNum != nil {
		db, _ := db2.NewDB()
		defer db.Close()
		db.Where("id = ?", num).Delete(new(models.Shop))
		ctx.JSON(200, gin.H{
			"code": 200,
			"msg":  "删除成功",
		})
	} else {
		ctx.JSON(404, gin.H{
			"code": 404,
			"msg":  "未找到",
		})
	}
}
